package com.huawei.cloudservice;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.hwid.api.common.e;
import com.huawei.hwid.api.common.f;
import com.huawei.hwid.api.common.o;
import com.huawei.hwid.core.c.a;
import com.huawei.hwid.core.d.b;
import com.huawei.hwid.core.d.g;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.encrypt.c;
import java.util.ArrayList;
import java.util.List;

public class CloudAccountManager {
    public static final int ACCOUNT_MANAGER_LOGOUT = 1;
    public static final String ACTION_HWID_ACCOUNT_REMOVE = "com.huawei.hwid.ACTION_REMOVE_ACCOUNT";
    public static final int FLAG_BIND_ACCOUNT_CARD_VERIFY = 4;
    public static final int FLAG_BIND_CARD_VERIFY = 3;
    public static final int FLAG_IDENTY_CAM_AND_FACE_OCR_VERIFY = 5;
    public static final int FLAG_IDENTY_CAM_VERIFY = 2;
    public static final int FLAG_REAL_NAME_VERIFY = 0;
    public static final int FLAG_SIMPLE_IDENTY_VERIFY = 1;
    public static final String KEY_ACCOUNT_NAME = "accountName";
    public static final String KEY_ACCOUNT_TYPE = "accountType";
    public static final String KEY_ACTIVATE_VIP = "activateVip";
    public static final String KEY_AIDL = "AIDL";
    public static final String KEY_APP_ID_WEB = "key_app_id_to_web";
    public static final String KEY_CHECK_SIM_STATUS = "check_sim_status";
    public static final String KEY_CHOOSE_WINDOW = "chooseWindow";
    public static final String KEY_DEVICEID = "deviceId";
    public static final String KEY_DEVICEINFO = "deviceInfo";
    public static final String KEY_DEVICE_TYPE = "deviceType";
    public static final String KEY_ISO_COUNTRY_CODE = "countryIsoCode";
    public static final String KEY_IS_TRANS_NAVIGATION_BAR = "isTransNavigationBar";
    public static final String KEY_LOGININFO = "userLoginInfo";
    public static final String KEY_LOGIN_CHANNEL = "loginChannel";
    public static final String KEY_LOGIN_USERNAME = "loginUserName";
    public static final String KEY_NEEDAUTH = "needAuth";
    public static final String KEY_REMOVED_ACCOUNT_NAME = "removedAccountName";
    public static final String KEY_REQCLIENTTYPE = "reqClientType";
    public static final String KEY_REQUESTCODE = "requestcode";
    public static final String KEY_RESULT_CODE = "result_code";
    public static final String KEY_SCOPE = "scope";
    public static final String KEY_SERVICEFLAG = "serviceFlag";
    public static final String KEY_SERVICE_COUNTRY_CODE = "serviceCountryCode";
    public static final String KEY_SERVICE_TOKEN = "serviceToken";
    public static final String KEY_SERVICE_TOKEN_WEB = "key_service_token_to_web";
    public static final String KEY_SITEID = "siteId";
    public static final String KEY_ST_STATUS = "STValidStatus";
    public static final String KEY_SUB_DEVICEID = "subDeviceId";
    public static final String KEY_USERACCOUNTINFO = "userAccountInfo";
    public static final String KEY_USERID = "userId";
    public static final String KEY_USERINFO = "userInfo";
    public static final String KEY_USER_ACCOUNT_WEB = "key_user_account_to_web";
    public static final String KEY_UUID = "uuid";
    public static final String KEY_VERSION_NAME = "versionName";

    public static void getAccountsByType(Context context, String str, Bundle bundle, LoginHandler loginHandler) {
        e.a(context, str, bundle, loginHandler);
    }

    public static void getForgotPwdIntent(Context context, int i, int i2, boolean z, IntentResultHandler intentResultHandler) {
        f.a(context, i, i2, z, intentResultHandler);
    }

    public static void logout(Context context, String str, String str2, Bundle bundle, LogoutHandler logoutHandler) throws RuntimeException {
        f.a(context, str, str2, bundle, logoutHandler);
    }

    public static void setLogoutIntent(Context context, Intent intent, int i, CloudRequestHandler cloudRequestHandler) {
        e.a(context, intent, i, cloudRequestHandler);
    }

    public static void setLogoutIntent(Context context, Intent intent, int i, int i2, CloudRequestHandler cloudRequestHandler) {
        e.a(context, intent, i, i2, cloudRequestHandler);
    }

    @Deprecated
    public static boolean checkIsInstallHuaweiAccount(Context context) {
        return o.b(context);
    }

    @Deprecated
    public static String getCurrLoginUserName(Context context) {
        return e.c(context);
    }

    public static void quickLogin(Context context, LoginHandler loginHandler) {
        quickLogin(context, null, loginHandler);
    }

    public static void quickLogin(Context context, String str, LoginHandler loginHandler) {
        e.a(context, str, loginHandler);
    }

    public static void clearAccountData(Context context) {
        e.b(context);
    }

    @Deprecated
    public static CloudAccount getCloudAccountByUserId(Context context, String str) {
        return e.b(context, str);
    }

    public static void getCloudAccountByUserId(Context context, String str, LoginHandler loginHandler) {
        e.b(context, str, loginHandler);
    }

    @Deprecated
    public static void logoutHwIdByUserId(Context context, String str, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        e.a(context, str, cloudRequestHandler, bundle);
    }

    @Deprecated
    public static void checkPassWord(Context context, String str, String str2, String str3, String str4, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        e.a(context, str, str2, str3, str4, cloudRequestHandler, bundle);
    }

    @Deprecated
    public static boolean isThirdAccount(String str) {
        return b.e(str);
    }

    @Deprecated
    public static void getVerifiedPhoneOrEmail(Context context, String str, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        f.a(context, str, cloudRequestHandler, bundle);
    }

    public static void release(Context context, Bundle bundle) {
        e.a(context, bundle);
    }

    @Deprecated
    public static void initial(Context context, Bundle bundle, CloudRequestHandler cloudRequestHandler) {
        e.a(context, bundle, cloudRequestHandler);
    }

    public static void updateHwId(Context context, Bundle bundle, CloudRequestHandler cloudRequestHandler) {
        e.b(context, bundle, cloudRequestHandler);
    }

    @Deprecated
    public static long getLoginCount(Context context) {
        return f.a(context);
    }

    public static Intent getPwdVerifyIntent() {
        return e.a();
    }

    public static void loginSystemAccount(Activity activity, LoginHandler loginHandler, int i) {
        if (activity != null && loginHandler != null) {
            e.a(activity, loginHandler, i, activity.getPackageName());
        }
    }

    @Deprecated
    public static void storeHwAccount(Context context, String str, String str2, HwAccount hwAccount, Bundle bundle) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "context is null", true);
        } else if (hwAccount == null || TextUtils.isEmpty(str)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "hwAccount or appId is null", true);
        } else {
            hwAccount.c(str);
            List arrayList = new ArrayList();
            arrayList.add(hwAccount);
            String a = a(str2);
            g.a(context, a);
            try {
                com.huawei.hwid.c.a.b.a(context, a, arrayList, true);
            } catch (Exception e) {
                com.huawei.hwid.core.d.b.e.c("CloudAccountManager", "Exception", true);
            }
        }
    }

    @Deprecated
    public static Bundle getHwAccount(Context context, String str, String str2) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "context is null", true);
            return null;
        }
        List<HwAccount> a = com.huawei.hwid.c.a.b.a(a(str2), context, true);
        if (a.isEmpty()) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "there is no account, get account failed", true);
        } else if (TextUtils.isEmpty(str)) {
            return ((HwAccount) a.get(0)).t();
        } else {
            List arrayList = new ArrayList();
            for (HwAccount hwAccount : a) {
                if (hwAccount != null && hwAccount.c().equals(str)) {
                    arrayList.add(hwAccount);
                }
            }
            if (!arrayList.isEmpty()) {
                return ((HwAccount) arrayList.get(0)).t();
            }
        }
        return null;
    }

    @Deprecated
    public static void storeAccessToken(Context context, String str) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "context is null", true);
        } else if (TextUtils.isEmpty(str)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "accessToken is null, store accessToken failed", true);
        } else {
            a.a(context).b("accessToken", c.b(context, str));
        }
    }

    @Deprecated
    public static String getAccessToken(Context context) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "context is null", true);
            return "";
        }
        String a = a.a(context).a("accessToken", "");
        if (TextUtils.isEmpty(a)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "accessToken is null, get accessToken failed", true);
            return a;
        }
        String c = c.c(context, a);
        if (TextUtils.isEmpty(c)) {
            return c.a(context, a);
        }
        return c;
    }

    @Deprecated
    public static void deleteAccessToken(Context context) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountManager", "context is null", true);
        } else {
            a.a(context).a("accessToken");
        }
    }

    private static String a(String str) {
        if (TextUtils.isEmpty(str)) {
            return new StringBuffer("app_account").append(".xml").toString();
        }
        return new StringBuffer("app_account").append("_").append(str).append(".xml").toString();
    }

    @Deprecated
    public static boolean isSupportFingerprint(Context context, Bundle bundle) {
        return com.huawei.hwid.api.common.apkimpl.a.a(context, bundle);
    }

    @Deprecated
    public static void checkHwIdPassword(Context context, String str, boolean z, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        e.a(context, str, z, cloudRequestHandler, bundle);
    }

    public static void checkPasswordByUserId(Context context, String str, String str2, String str3, String str4, String str5, String str6, String str7, CloudRequestHandler cloudRequestHandler, Bundle bundle, int i) {
        e.a(context, str, str2, str3, str4, str5, str6, str7, cloudRequestHandler, bundle, i);
    }
}
